package com.bwie.home.backstage.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.home.common.utils.PageUtils;
import com.bwie.home.common.utils.Query;

import com.bwie.home.backstage.dao.SchoolDao;
import com.bwie.home.backstage.entity.SchoolEntity;
import com.bwie.home.backstage.service.SchoolService;


@Service("schoolService")
public class SchoolServiceImpl extends ServiceImpl<SchoolDao, SchoolEntity> implements SchoolService {

    @Override
    public PageUtils queryPage(Map<String, Object> params, SchoolEntity school) {
        QueryWrapper<SchoolEntity> wrapper = new QueryWrapper<>();
        if (school!=null){
            if (school.getProvinceName()!=null && !school.getProvinceName().equals("")){
                wrapper.eq("province_name",school.getProvinceName());
            }
            if (school.getCityName()!=null && !school.getCityName().equals("")){
                wrapper.eq("city_name",school.getCityName());
            }
            if (school.getSchoolName()!=null && !school.getSchoolName().equals("")){
                wrapper.like("school_name",school.getSchoolName());
            }
        }
        IPage<SchoolEntity> page = this.page(
                new Query<SchoolEntity>().getPage(params),
                wrapper
        );

        //获取区域
        List<SchoolEntity> records = page.getRecords();
        for (SchoolEntity record : records) {
            record.setAddress(record.getProvinceName()+"-"+record.getCityName()+"-"+record.getDistrictName());
        }
        page.setRecords(records);
        return new PageUtils(page);
    }

}